<template>
  <component is="a-modal" v-model:visible="visible" width="50%" :title="title" :mask-closable="false"
    :ok-loading="loading" @cancel="close" @before-ok="submit">
    <div >
      <a-alert style="display: flex;flex-direction: column;margin-bottom: 20px;" :show-icon="false">
        1、订单本身记录会转给新会员 </br>
        2、关联的支付记录会转移 </br>
        3、发货记录会转移(收货地址不变) </br>
        4、积分流水双方会重新计算 </br>
      </a-alert>
      <a-form ref="formRef" :model="formData" :rules="rules" :auto-label-width="true">
        <a-form-item label="订单记录" field="id">
          <a-input v-model="formData.id" placeholder="请输入" />
        </a-form-item>
        <a-form-item label="转給新会员名" field="user">
          <div style="width:100%">
            <a-input v-model="formData.user" placeholder="请输入" />
            <div style="margin-top: 10px;color:grey">如果新会员名已經使用完了这笔金额, 则扣除新会员名的余额时可能會出现负数情況</div>
          </div>
        
        </a-form-item>
        <a-form-item label="操作密码" field="admin_pay_password">
          <a-input-password v-model="formData.admin_pay_password" placeholder="请输入" />
        </a-form-item>
        <a-form-item label="谷歌验证码" field="google_code">
          <a-input v-model="formData.google_code" placeholder="请输入" />
        </a-form-item>
      </a-form>
    </div>
  </component>
</template>
<script setup>
import { onMounted, ref, reactive, computed, watch } from 'vue'
import funApi from '@/api/message/tool'
import { Message } from '@arco-design/web-vue'
import { throttle } from 'lodash';
import tool from '@/utils/tool'
const emit = defineEmits(["success"]);
const formRef = ref()
const visible = ref(false);
const title = ref('')
const loading = ref(false);
const formData = reactive({
  id: '',
  user: '',
  admin_pay_password: '',
  google_code:'',
})
const rules = ref({
  user: [{ required: true, message: '请输入' }],
  id: [{ required: true, message: '请输入' }],
  admin_pay_password: [{ required: true, message: '请输入' }],
  google_code: [{ required: true, message: '请输入' }],
});
const open = async (data) => {
  visible.value = true;
  formRef.value.resetFields()
  title.value='转移订单(代付)记录'
  getParams()
}
const submit = async (done) => {
  const validate = await formRef.value?.validate()
  if (!validate) {
    loading.value = true
    try {
      let data = { ...formData }
      let result = await funApi.tool_tranform_order(data)
      if (result.code === 200) {
        Message.success('操作成功')
        emit('success')
        done(true)
      }
      setTimeout(() => {
        loading.value = false
      }, 500)
    } catch {
      loading.value = false
    }
  }
  done(false)

}
const paramsData = ref({})
const getParams = async () => {
  // const { data } = await memberApi.update_pv_params(formData.id)
  // paramsData.value = { ...data }
}
defineExpose({ open });
</script>